package jhlee42.swing;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Toolkit;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JPasswordField;
import javax.swing.SwingUtilities;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class JoinMember extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField uid;
	private JPasswordField pwd;
	private JPasswordField repwd;
	private JTextField zipcode;
	private JTextField addr;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			JoinMember dialog = new JoinMember();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public JoinMember() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(JoinMember.class.getResource("/images/icon/icon.png")));
		setTitle("회원가입");
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		JLabel label = new JLabel("아이디");
		
		uid = new JTextField();
		uid.setColumns(10);
		
		JButton dupBtn_1 = new JButton("중복확인");
		
		JLabel lblNewLabel = new JLabel("비밀번호");
		
		JLabel lblNewLabel_1 = new JLabel("비밀번호 확인");
		
		pwd = new JPasswordField();
		
		repwd = new JPasswordField();
		
		JLabel lblZipcode = new JLabel("우편번호");
		
		JLabel lblAddr = new JLabel("기본주소");
		
		zipcode = new JTextField();
		zipcode.setEditable(false);
		zipcode.setColumns(10);
		
		addr = new JTextField();
		addr.setColumns(10);
		
		JButton btnNewButton = new JButton("우편번호 찾기");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				/***********************************************************************************************************************/
				// 이벤트 발생	
				JoinMember parent = (JoinMember)SwingUtilities.windowForComponent((Component)e.getSource()); // getSource 버튼을 눌렀을 때 발생
				FindZipcode modal = new FindZipcode(parent);
				modal.setVisible(true);
				/***********************************************************************************************************************/
				
				
				
				
			}
		});
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(lblNewLabel_1)
						.addComponent(lblNewLabel)
						.addComponent(label)
						.addComponent(lblAddr)
						.addComponent(lblZipcode))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(addr, GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
						.addComponent(zipcode, GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
						.addComponent(repwd, GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
						.addComponent(pwd, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
						.addComponent(uid, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(dupBtn_1)
						.addComponent(btnNewButton))
					.addGap(44))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(label)
						.addComponent(uid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(dupBtn_1))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(pwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(repwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(zipcode, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblZipcode)
						.addComponent(btnNewButton))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(addr, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblAddr))
					.addContainerGap(29, Short.MAX_VALUE))
		);
		contentPanel.setLayout(gl_contentPanel);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("   확인   ");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("   취소   ");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	} // 생성자
	
	/***********************************************************************************************************************/
	// FindZipcode에서 작성된 주소정보를 JoinMember 의 zipcode addr로 보내기 위해 작성한 메서드
	// FindZipcode가 호출함!! (중요)
	public void sendZipcode(String zip){
//		zipcode.setText("텍스트를 삽입하려면 zipcode.setText 로 넣어준다..");
//		addr.setText("텍스트를 삽입하려면 addr.setText 로 넣어준다..");
		zipcode.setText(zip.split(" ")[0]);
		addr.setText(zip.substring(8));
	}
	
	
	
	
} // class

















